export default {
    name:'mx-inline-player',
    
    data(){
        return {
            player:{
                muted:false,
                active:''
            },
        }
    },
    mounted(){
        window.addEventListener('scroll',()=>{
            if(this.player.active){
                let rect = this.player.active.getBoundingClientRect();
                if(rect.top < 0 && Math.abs(rect.top) >= rect.height || rect.top >= window.innerHeight){
                    this.player.active.pause();
                }
            }
        });
    },
    methods:{
        volumeChange(e){
            this.player.muted = e.currentTarget.muted
        },
        playVideo(e,item){
            if(this.player.active){
                this.player.active.pause();
            }
            if(item.play_status == 0){
                item.play_status = 1;
            }
            this.$el.querySelectorAll('video').forEach(item=>{
                item.pause();
                item.currentTime = 0;
            })
            let video = e.currentTarget.parentNode.querySelector('video');
            video.play();
            this.player.active = video;
        },
    }
}